package cate.common.table.pvp.guildwar.sheet;


import cate.common.table.ESheet;
import cate.common.table.pvp.guildwar.row.GuildWarTreasureRow;
import cate.common.util.random.RWList;
import easy.java.dev.note.NoteClass;

import java.util.ArrayList;
import java.util.List;

@NoteClass("宝库奖励")
public class GuildWarTreasureSheet extends ESheet<GuildWarTreasureRow> {

    @Override
    public String getSheetName() {
        return "宝库奖励";
    }

    @Override
    protected GuildWarTreasureRow buildRow() {
        return new GuildWarTreasureRow();
    }

    public List<GuildWarTreasureRow> findItems(int openDay) {
        List<GuildWarTreasureRow> result = new ArrayList<>();
        RWList<GuildWarTreasureRow> rwList = new RWList<>();
        for (GuildWarTreasureRow row : this.getList()) {
            if (openDay >= row.startDay && openDay <= row.endDay) {
                if (row.type == 1) {
                    result.add(row);
                } else {
                    rwList.add(row);
                }
            }
        }
        if (!rwList.isEmpty()) {
            GuildWarTreasureRow randomRow = rwList.setup().get();
            if (randomRow != null) {
                result.add(randomRow);
            }
        }
        return result;
    }
}
